#use "calc_parser.ml";;

(* let input = "12+34/(4-2)";; *)
(* let input = "5x*3";; *)
(* let input = "4*x2";; *)
let input = "(-)";;

let test_eof i p = (
	let p2 = Parser.post i '\x1a' p in
	if not (Parser.accepted p2) then (
		raise (Failure "NOT ACCEPTED EOF!!")
	)
);;

let p = ref (Parser.create ());;
let length = String.length input;;
test_eof 0 !p;;
for i = 0 to length - 1 do
	p := Parser.post (i + 1) input.[i] !p;
	test_eof (i + 2) !p
done;;
let p = Parser.post (length + 1) '\x1a' !p;;

flush stderr;;

if Parser.accepted p then (
	begin match Parser.result p with
	| Some (AST.Sub (None, 2, None)) ->
		begin match Parser.errors p with
		| [3, Parser.Expected_expr; 2, Parser.Expected_expr] ->
			print_string "OK.\n";
		| _ ->
			raise (Failure "BAD ERRORS DETECTED!!")
		end
	| _ ->
		raise (Failure "BAD RESULT!!")
	end
) else (
	raise (Failure "NOT ACCEPTED!!")
);;
